package com.fenyin.samples.study.jdk.datastruct.list;  

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
  
public class ListTest {
	
	private static final Log log = LogFactory.getLog(ListTest.class);
	
	private static void linedListTest(){

		LinkedList<String> list = new LinkedList<String>();
		list.addFirst("fengzhichao1");
		list.addFirst("fengzhichao2");
		list.addFirst("fengzhichao3");
		list.addFirst("fengzhichao4");
		list.addFirst("fengzhichao5");
		for(int i = 0;i<list.size();i++){
			log.info("addFirst index "+i+" "+list.get(i));
		}
		list.removeFirst();
		list.removeFirst();
		for(int i = 0;i<list.size();i++){
			log.info("removeFirst-2 index "+i+" "+list.get(i));
		}
		list.removeFirst();
		list.removeFirst();
		list.removeFirst();
		list.addLast("huangzexiang1");
		list.addLast("huangzexiang2");
		list.addLast("huangzexiang3");
		list.addLast("huangzexiang4");
		for(int i = 0;i<list.size();i++){
			log.info("addLast index "+i+" "+list.get(i));
		}
	}
	
	private static void cycleLinedListTest(){

		CycleLinkedList<String> list = new CycleLinkedList<String>();
		list.addFirst("fengzhichao1");
		list.addFirst("fengzhichao2");
		list.addFirst("fengzhichao3");
		list.addFirst("fengzhichao4");
		list.addFirst("fengzhichao5");
		for(int i = 0;i<list.size();i++){
			log.info("addFirst index "+i+" "+list.get(i));
		}
		list.removeFirst();
		list.removeFirst();
		for(int i = 0;i<list.size();i++){
			log.info("removeFirst-2 index "+i+" "+list.get(i));
		}
		list.removeFirst();
		list.removeFirst();
		list.removeFirst();
		list.addLast("huangzexiang1");
		list.addLast("huangzexiang2");
		list.addLast("huangzexiang3");
		list.addLast("huangzexiang4");
		for(int i = 0;i<list.size();i++){
			log.info("addLast index "+i+" "+list.get(i));
		}
	}
	
	private static void doubleLinedListTest(){

		DoubleLinkedList<String> list = new DoubleLinkedList<String>();
		list.addFirst("fengzhichao1");
		list.addFirst("fengzhichao2");
		list.addFirst("fengzhichao3");
		list.addFirst("fengzhichao4");
		list.addFirst("fengzhichao5");
		for(int i = 0;i<list.size();i++){
			log.info("addFirst index "+i+" "+list.get(i));
		}
		list.removeFirst();
		list.removeFirst();
		for(int i = 0;i<list.size();i++){
			log.info("removeFirst-2 index "+i+" "+list.get(i));
		}
		list.removeFirst();
		list.removeFirst();
		list.removeFirst();
		list.addLast("huangzexiang1");
		list.addLast("huangzexiang2");
		list.addLast("huangzexiang3");
		list.addLast("huangzexiang4");
		for(int i = 0;i<list.size();i++){
			log.info("addLast index "+i+" "+list.get(i));
		}
	}
	
	private static void cycleDoubleLinedListTest(){

		CycleDoubleLinkedList<String> list = new CycleDoubleLinkedList<String>();
		list.addFirst("fengzhichao1");
		list.addFirst("fengzhichao2");
		list.addFirst("fengzhichao3");
		list.addFirst("fengzhichao4");
		list.addFirst("fengzhichao5");
		for(int i = 0;i<list.size();i++){
			log.info("addFirst index "+i+" "+list.get(i));
		}
		list.removeFirst();
		list.removeFirst();
		for(int i = 0;i<list.size();i++){
			log.info("removeFirst-2 index "+i+" "+list.get(i));
		}
		list.removeFirst();
		list.removeFirst();
		list.removeFirst();
		list.addLast("huangzexiang1");
		list.addLast("huangzexiang2");
		list.addLast("huangzexiang3");
		list.addLast("huangzexiang4");
		for(int i = 0;i<list.size();i++){
			log.info("addLast index "+i+" "+list.get(i));
		}
	}
	
	public static void main(String[] args){
//		cycleLinedListTest();
//	    doubleLinedListTest();
		cycleDoubleLinedListTest();
	}
}
